<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 父类Animal */
      class Animal {
        // 构造函数
        constructor(type, food) {
          // this=正在构建的animal对象
          this.type = type;
          this.food = food;
        }

        /* Animal原型共享给所有实例的【实例方法】,普通函数（this即调用的主语） */
        // Animal.prototype.eat = function(){}
        eat() {
          //this是调用的主语
          console.log(`一只${this.type}正在享用${this.food}`);
        }
      }

      /* Animal的子类Person */
      class Person extends Animal {
        constructor(name, age) {
          // 在子类的构造器访问this之前 必须先调用父类的构造器函数
          // Animal.call(this,"人", "大米饭")
          super("人", "大米饭");
          
          this.name = name;
          this.age = age;
        }

        /* 【实例方法】think */
        think() {
          console.log(`${this.name}正在思考`);
        }
      }
    </script>

    <script>
      // const animal = new Animal("狗狗", "大骨头");
      // animal.eat();
      // console.log(animal);

      const person = new Person("张三丰", 60);
      console.log(person);
      person.think();
      person.eat();
    </script>
  </body>
</html>
